﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SolutionGenerator
{
    public partial class SolutionGeneratorForm : Form
    {

        #region Variable
        private SolutionConfiguration solutionInfo = new SolutionConfiguration();
        private WizardEngine wiz;
        #endregion

        #region WizardSupport
        public SolutionGeneratorForm()
        {
            InitializeComponent();
        }
        private List<UserControlParent> BuiltWizardPages
        {
            get
            {
                List<UserControlParent> result = new List<UserControlParent>();
                result.Add(new WizardLoadConfiguration(solutionInfo));
                result.Add(new WizardGetConnectionString(solutionInfo));
                result.Add(new WizardGetTable(solutionInfo));
                result.Add(new WizardProcessFKChilds(solutionInfo));
                result.Add(new WizardGetTemplates(solutionInfo));
                result.Add(new WizardGeneratingCode(solutionInfo));
                //result.Add(new WizardCompleteReport(solutionInfo));
                return result;
            }
        }
        private void SolutionGeneratorForm_Load(object sender, EventArgs e)
        {
            wiz = new WizardEngine(SolutionGeneratorMainPanel, WizardStep.W01_LoadConfiguration, BuiltWizardPages);
            SetupWizardDisplay();
        }
        private void SetupWizardDisplay()
        {
            SolutionGeneratorButtonNext.Enabled = wiz.IsNextAvailable;
            SolutionGeneratorButtonFinish.Enabled = !wiz.IsNextAvailable;
            SolutionGeneratorButtonPrevious.Enabled = wiz.IsPrevAvailable;
            SolutionGeneratorWizardTitle.Text = wiz.WizardTitle;
            SolutionGeneratorToolStripProgressLabel.Text = string.Format("Page {0} of {1}", wiz.GetCurrentPage, wiz.GetTotalPage);
        }
        private void SolutionGeneratorButtonNext_Click(object sender, EventArgs e)
        {
            wiz.NextPage();
            SetupWizardDisplay();
        }
        private void SolutionGeneratorButtonPrevious_Click(object sender, EventArgs e)
        {
            wiz.PreviousPage();
            SetupWizardDisplay();
        }
        private void SolutionGeneratorButtonFinish_Click(object sender, EventArgs e)
        {
            SaveConfigName.InitialDirectory = Environment.CurrentDirectory;
            if (SaveConfigName.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                using (SerializeProcessing<SolutionConfiguration> serial =
                    new SerializeProcessing<SolutionConfiguration>(solutionInfo))
                    File.WriteAllText(SaveConfigName.FileName, serial.Serialize);
            }
        }
        #endregion

    }
}